<template>
  <transition name="fade">
    <div v-if="show" class="drawerLeft">
      <div class="head-title">
        <span>{{ name }}</span>
        <el-icon style="cursor: pointer" @click="closeDrawer"
          ><Close />
        </el-icon>
      </div>

      <pathCom v-if="type == 'lujing'"></pathCom>
      <communityDetectionCom v-if="type == 'community'"></communityDetectionCom>
      <nodeImportantCom v-if="type == 'nodeImportant'"></nodeImportantCom>
    </div>
  </transition>
</template>

<script lang="ts" setup>
// vue
import { emitter } from "@/utils/mitt"; // 组件通讯
import {
  clearAllStats,
  returnNodeSize,
} from "@/views/associationAnalysis/canvas/components/canvasG6/common/index";

// 动画css
import "animate.css/animate.min.css";

// 组件
import { Close } from "@element-plus/icons-vue";
import pathCom from "./components/path.vue";
import communityDetectionCom from "./components/communityDetection.vue";
import nodeImportantCom from "./components/nodeImportant.vue";

const graphModule = inject("graphModule");

let show = ref(false);
let name = ref("");
let type = ref(null); // 组件区分
// 顶部操作栏保存按钮事件监听触发
emitter.on("showDrawer", (obj) => {
  console.log(obj, "showDrawer");
  show.value = true;
  name.value = obj.name;
  type.value = obj.type;
});

/** 关闭左侧弹窗 */
const closeDrawer = () => {
  show.value = false;
  clearAllStats();
  graphModule.value.removeHulls();
  returnNodeSize(); // 将节点还原成初始大小
};
</script>

<style lang="scss" scoped>
.drawerLeft {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  box-sizing: border-box;
  width: 372px;
  height: 100%;
  padding: 16px;
  overflow: hidden;
  overflow-y: auto;
  background: #fff;
  border-left: 1px solid #edeff4;
  border-radius: 2px 0 0 2px;
  box-shadow: 0 2px 8px 0 rgb(13 22 50 / 10%);

  .head-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
  }
}
</style>
